// app.ts
import './guard'
const miniShopPlugin = requirePlugin('mini-shop-plugin');

App<IAppOption>({
  globalData: {
    navBarHeight: 0, // 导航栏高度
    menuRight: 0, // 胶囊距右方间距（方保持左、右间距一致）
    menuBottom: 0, // 胶囊距底部间距（保持底部间距一致）
    menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
    menuTop: 0,//胶囊距顶部高度
    statusBarHeight: 0,//状态栏高度
    menuWidth: 0,//
    pageHeight: 0,//windowHeight - navBar  = 页面高度
    windowWidth: 0,//屏幕宽度
    system: '',//
    safeArea: '',
    // play-page
    currentEnterPriseID: null,//当前企业
    currentPlayVideoID: null,//当前播放监控id
    currentPlayElv: null,//当前播放监控所属elv
    CameraOrigin:null,
    token: '',
    code: '',
    userInfo: {},
    currentTabBar: 1,//1：小马视界(直播)2：企业号
    category:{},//小马视界滑动菜单分类
  },
  onLaunch() {
    miniShopPlugin.initApp(this, wx);
    const that = this;
    wx.login({
      success(res) {
        that.globalData.code = res.code
      }
    })

    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();

    // 胶囊按钮位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    // 导航栏高度 = 状态栏到胶囊的间距（胶囊距上距离-状态栏高度） * 2 + 胶囊高度 + 状态栏高度
    that.globalData.navBarHeight = (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 + menuButtonInfo.height + systemInfo.statusBarHeight;
    that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
    that.globalData.menuBottom = menuButtonInfo.top - systemInfo.statusBarHeight;
    that.globalData.menuHeight = menuButtonInfo.height;
    that.globalData.menuTop = menuButtonInfo.top;
    that.globalData.statusBarHeight = systemInfo.statusBarHeight;
    that.globalData.menuWidth = menuButtonInfo.width;
    that.globalData.pageHeight = systemInfo.windowHeight - ((menuButtonInfo.top - systemInfo.statusBarHeight) * 2 + menuButtonInfo.height + systemInfo.statusBarHeight);
    that.globalData.windowWidth = systemInfo.windowWidth;
    that.globalData.system = systemInfo.system;
    that.globalData.safeArea = systemInfo.safeArea;
    console.log(systemInfo.safeArea);

    // 初始化用户信息和登录状态
    that.globalData.token = wx.getStorageSync('token')
    that.globalData.userInfo = wx.getStorageSync('userInfo')
  },
})